package com.lovo.test.ATM;

import com.lovo.test.JAVAIO.Io.FileUtil;
import com.lovo.test.Util.Util;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

//ATM界面
public class ATM extends JFrame  {


    private ArrayList <User> users = new ArrayList();//创建用户集合
    private User userName;//登录成功的用户属性


    //以下是图片封装
    private Image bjImg= Util.getImage("/ATMimages/background.jpg");//背景图


   //以下是布局所有界面
    private CardLayout cardLayout = new CardLayout();//卡片布局对象
    private MenuPanel menuPanel = new MenuPanel(this);//产生菜单对象
    private LoginPanel loginPanel = new LoginPanel(this);//产生登录对象
    private TakePanel takePanel= new TakePanel(this);//产生取款对象
    private CheckPanel checkPanel = new CheckPanel(this);//产生查询对象
    private StorePanel storePanel = new StorePanel(this);//产生存款对象
    private TurnPanel turnPanel = new TurnPanel(this);//产生转账对象
    private CorrectPanel correctPanel = new CorrectPanel(this);//产生改密对象



    public ATM(){



        //背景图片引入
        this.setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintBorder(g);
                g.drawImage(bjImg,0,0,800,600,this);
            }
        });




        //卡片布局
        this.setLayout(cardLayout);
        this.add("登录",loginPanel);//添加登陆界面
        this.add("菜单",menuPanel);//添加菜单界面
        this.add("取款",takePanel);//添加取款界面
        this.add("存款",storePanel);//添加存款界面
        this.add("查询",checkPanel);//添加查询界面
        this.add("转账",turnPanel);//添加转账界面
        this.add("改密",correctPanel);//添加改密界面



        //窗口大小
        this.setSize(800,600);
        //窗口名称
        this.setTitle("ATM取款机");
        //关闭结束程序
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //窗口居中
        this.setLocationRelativeTo(null);
        //窗口可见
        this.setVisible(true);
    }

    //用户数据初始化
    public void init(){
       users= (ArrayList<User>) FileUtil.readObject("D:/ATM.txt");
    }
    //用户数据保存
    public void preserve(){
        FileUtil.writeObject("D:/ATM.txt",users);
    }


    //主函数
    public static void main(String[] args) {
        new ATM().init();
    }


    //页面跳转方法
    public void switchPanel(String name){
        cardLayout.show(this.getContentPane(),name);
    }


    //以下是get，set
    //用户集合的get，set
    public ArrayList<User> getUsers() {
        return users;
    }

    public void setUsers(ArrayList<User> users) {
        this.users = users;
    }


    //查询的访问修改方法

    public CheckPanel getCheckPanel() {
        return checkPanel;
    }

    public void setCheckPanel(CheckPanel checkPanel) {
        this.checkPanel = checkPanel;
    }

    //登陆的访问修改方法

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public void setLoginPanel(LoginPanel loginPanel) {
        this.loginPanel = loginPanel;
    }

    //登陆成功的用户对象get.set方法


    public User getUserName() {
        return userName;
    }

    public void setUserName(User userName) {
        this.userName = userName;
    }

    //用户数据保存的get.set方法

}
